package com.cms.counsel.action;

import java.util.ArrayList;
import java.util.List;

import com.cms.counsel.model.Counsel;
import com.jframe.sys.controller.ExtendAction;
import com.jframe.sys.controller.utils.DicCache;
import com.jframe.sys.controller.utils.JsBuilder;
import com.jframe.sys.controller.utils.TabmCache;
import com.jframe.sys.utils.JsonUtil;
import com.jframe.sys.webui.Columns;
import com.jframe.sys.webui.Editor;
import com.jframe.sys.webui.Grid;

public class CounselAction extends ExtendAction {
	private static String ACTION="counselAction";
	private static String SERVICE = "counselService";
	private static Class<Counsel> CLAZZ = Counsel.class;
	public void list(){
		List<Columns> frozenColumns = new ArrayList<Columns>();// 固定列
		List<Columns> commonColumns = new ArrayList<Columns>();// 活动列
		frozenColumns.add(new Columns("ck", "", 40, ""));
		//commonColumns.add(new Columns("id", "编号", 100, ""));
		frozenColumns.add(new Columns("questTitle", "问题标题", 300, ""));
		//commonColumns.add(new Columns("question", "问题内容", 400, ""));
		commonColumns.add(new Columns("askTime", "提问时间", 120, ""));
		commonColumns.add(new Columns("typeId", "问答类别", 120, new Editor("combobox",true),TabmCache.getComboboxJson("sm_cms_counselType")));
		commonColumns.add(new Columns("isConmmon", "是否常见", 120, new Editor("combobox",true),DicCache.getComboboxJson("dm_cms_isConmmon")));		
		if(this.pageInfo.getPageTabId(request).equals("1")){
			commonColumns.add(new Columns("isReview", "是否回复", 120, new Editor("combobox",true),DicCache.getComboboxJson("dm_cms_isReview")));			
		}else{
			//commonColumns.add(new Columns("content", "回复", 300, ""));
			commonColumns.add(new Columns("reviewTime", "回复时间", 120, ""));
			commonColumns.add(new Columns("reviewUser", "回复人员", 120, ""));
		}
		Grid grid = new Grid();
		grid.setUrl(this.getUrl(ACTION+".do?method=load"));
		String js = JsBuilder.getJsStr(frozenColumns, commonColumns, grid);
		this.request.setAttribute("js", js);
		this.forward("/cms/counsel/list/counselList.jsp");
	}
	
	public void load(){
		baseLoad(SERVICE, CLAZZ);
	}
	
	public Object beforeSave(Object obj){
		Counsel counsel = (Counsel)obj;
		String content = request.getParameter("content");
		counsel.setContent(content);
		String question = request.getParameter("question");
		counsel.setQuestion(question);
		return counsel;
	}
	
	public void save() {
		baseSave(SERVICE, CLAZZ);
	}
	

	public void delete() {
		baseDelete(SERVICE);
	}
	
	public void afterDelete(String ids){

	}

	public void getObjById() {
		print(JsonUtil.obj2Json(this.getObject(SERVICE)));
	}
}
